import { Map } from "immutable";
import {
  CHANGE_DETAIL_COMMENT,
  CHANGE_NEW_COMMENT,
  CHANGE_DETAIL_NOTE,
  CHANGE_DETAIL_NOTE_ID,
  CHANGE_DETAIL_NOTE_USER_ID,
} from "./constant";

const defaultState = Map({
  noteId: "",
  noteUserId: "",
  detailNote: {},
  commentData: [],
});

function reducer(state = defaultState, { type, data }) {
  switch (type) {
    case CHANGE_DETAIL_NOTE_USER_ID:
      return state.set("noteUserId", data);
    case CHANGE_DETAIL_NOTE_ID:
      return state.set("noteId", data);
    case CHANGE_DETAIL_COMMENT:
      return state.set("commentData", data);
    case CHANGE_NEW_COMMENT:
      return state.set("commentData", [...state.get("commentData"), data]);
    case CHANGE_DETAIL_NOTE:
      return state.set("detailNote", data);
    default:
      return state;
  }
}

export default reducer;
